package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.CarDispatchBill;
import com.eling.elcms.travel.model.CheckInCar;
import com.eling.elcms.travel.service.ICheckInCarManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class CheckInCarController extends BaseFormController {

	@Autowired
	private ICheckInCarManager carM;

	@RequestMapping("/api/checkincar/save")
	@ResponseBody
	public CheckInCar save(@ModelAttribute @ModelFilling CheckInCar car ) {
		return carM.save(car);
	}

	@RequestMapping("/api/checkincar/{pkCheckInCar}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkCheckInCar) {
		carM.remove(pkCheckInCar);
		return new Msg("删除成功");
	}

	@RequestMapping("/api/checkincar/query")
	@ResponseBody
	public List<CheckInCar> query(@ModelAttribute CheckInCar car) {
		return carM.query(car);
	}

	@RequestMapping("/api/checkincar/search*")
	@ResponseBody
	public List<CheckInCar> search(@ModelAttribute SearchCondition sc, @ModelAttribute CheckInCar car) {
		sc.setQueryCondition(car);
		return carM.search(sc);
	}

	@RequestMapping("/api/checkincar/confirm")
	@ResponseBody
	public CheckInCar confirm(@ModelAttribute @ModelFilling CheckInCar car,@ModelAttribute CarDispatchBill carDispatchBill) {
		return carM.confirm(car,carDispatchBill);
	}

	/**
	 * 查询车辆落实
	 * @param car
	 * @param startDate
	 * @param endDate
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/checkincar/queryall")
	@ResponseBody
	public List<CheckInCar> queryAll(@ModelAttribute CheckInCar car,
			@RequestParam(name = "startDate", required = false) Date startDate,
			@RequestParam(name = "endDate", required = false) Date endDate) {
		return carM.queryAll(car, startDate, endDate);
	}

}
